<template>
  <div class="identity">
    <div class="title">
      <p>请选择您的身份</p>
    </div>
    <div class="operate clearfix">
      <div
        class="auto auto-left"
        :class="[active === 0 && 'active']"
        @click="toCheck(0)"
      >
        <div class="auto-img">
          <img src="../../static/man.png" alt="个人" />
        </div>
        <label>
          <span class="checkbox" v-show="active === 0">
            <i class="el-icon-check"></i>
          </span>
          <span class="checkbox" v-show="active !== 0">&nbsp;</span>
          <span class="text">我要找工作</span>
        </label>
      </div>
      <div
        class="auto auto-right"
        :class="[active === 1 && 'active']"
        @click="toCheck(1)"
      >
        <div class="auto-img">
          <img src="../../static/company.png" alt="企业" />
        </div>
        <label>
          <span class="checkbox" v-show="active === 1">
            <i class="el-icon-check"></i>
          </span>
          <span class="checkbox" v-show="active !== 1">&nbsp;</span>
          <span class="text">我要招人</span>
        </label>
      </div>
    </div>
    <div class="submit">
      <button type="button" @click="submit">确认</button>
    </div>
  </div>
</template>

<script>
import { setUser } from '@/utils/cookie'
import { setUsersType } from '@/api/users'
export default {
  data () {
    return {
      active: 0,
    }
  },
  created () {
  },
  mounted () {
  },
  methods: {
    toCheck (data) {
      this.active = data;
    },
    toLogin () { // 登录
      this.$store.dispatch('user/toggleModal', {
        login: true
      })
    },
    submit () { // 选择个人/企业
      let userType = '';
      if (this.active === 0) { // 个人
        userType = 1;
      } else if (this.active === 1) { // 企业
        userType = 2;
      }
      setUsersType({
        type: userType
      }).then(res => {
        if (res.code === 200 || res.code === 1003 || res.code === 1004) {
          setUser(JSON.stringify(res.data))
          this.$store.dispatch('user/userInfo', res.data);
          this.$store.dispatch('user/toggleModal');
          this.$message.success(res.msg || '成功！')
        } else {
          this.$message.error(res.msg || '网络错误, 稍后再试！');
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.identity {
  height: 430px;
  padding: 30px 90px;
  .title {
    height: 50px;
    p {
      line-height: 50px;
      text-align: center;
      font-size: 21px;
      color: #333;
    }
  }
  .identity-wrap {
    margin: 20px 0;
    & > div {
      height: 55px;
      border-bottom: 1px solid #eee;
      input,
      p {
        line-height: 54px;
        height: 54px;
        color: #333;
        font-size: 16px;
      }
    }
    .phone {
      p {
        float: left;
        width: 80px;
      }
    }
    button {
      float: right;
      margin-top: 10px;
      width: 135px;
      height: 35px;
      border: 1px solid $base-color;
      background: #fff;
      border-radius: 4px;
      color: $base-color;
      &:hover {
        background: $base-color;
        color: #fff;
      }
    }
  }
  .operate {
    .auto-left {
      float: left;
    }
    .auto-right {
      float: right;
    }
    .auto {
      margin-top: 40px;
      .auto-img {
        margin-bottom: 10px;
        width: 145px;
        height: 145px;
        text-align: center;
        font-size: 0;
        border: 4px solid #eee;
        border-radius: 50%;
        overflow: hidden;
        background: #eee;
        img {
          height: 100%;
          margin-top: 5px;
        }
      }

      label {
        text-align: center;
        display: inline-block;
        width: 100%;
        padding-right: 10px;
        .checkbox {
          display: inline-block;
          height: 22px;
          line-height: 21px;
          width: 22px;
          border: 1px solid #d8d8d8;
          border-radius: 50%;
          text-align: center;
          i {
            vertical-align: text-bottom;
            color: $base-color;
            font-size: 18px;
            font-weight: 600;
          }
        }
        .text,
        a {
          font-size: 16px;
          color: #999;
          margin-left: 5px;
        }
      }
      &:hover,
      &.active {
        .auto-img,
        .text,
        a {
          border-color: $base-color;
          cursor: pointer;
          color: $base-color;
        }
      }
    }
  }
  .submit {
    margin-top: 50px;
    text-align: center;
    button {
      height: 45px;
      width: 230px;
      margin: 0 auto;
      background: $base-color;
      color: #fff;
      border: 1px solid $base-color;
      border-radius: 22.5px;
      font-size: 16px;
      &:hover {
        background: #fff;
        color: $base-color;
      }
    }
    p {
      margin-top: 10px;
      color: #999;
      font-size: 16px;
      text-align: center;
      &:hover {
        color: $base-color;
        cursor: pointer;
      }
    }
  }
}
</style>
